package com.xieyingwangluo.yxpart.api;

import com.xieyingwangluo.yxpart.bean.Result;
import com.xieyingwangluo.yxpart.entity.WorksheetModel;
import com.xieyingwangluo.yxpart.logic.WorkLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Api(tags = "worksheet接口")
@Controller
@RequestMapping(value = "/api/v1/worksheet")
public class WorksheetBaseRest extends BaseRest {
    @Autowired
    private WorkLogic workLogic;

    //根据id获取用户信息
    @ApiOperation(value = "根据id获取用户信息", notes = "根据id获取用户信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "工作表编号", required = true, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selO")
    public Result selO(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       @RequestParam("noid") String noid
    ) {
        return workLogic.getById(noid);
    }


    //模糊查询所有信息
    @ApiOperation(value = "查询所有工作", notes = "查询所有工作", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "工作表编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "part_id", value = "兼职编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userinfo_id", value = "用户信息编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "enroll_id", value = "报名编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "record_time", value = "录用时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "工作状态", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "completion", value = "工作工作完成度", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "payamount", value = "付款金额", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "time", value = "工作时长", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "makespan", value = "完工时间", required = false, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selA")
    public Result selA(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       WorksheetModel work) {
        return workLogic.selA(work);
    }

    //根据工作id修改工作状态（修改为已录用）
    @ApiOperation(value = "根据工作id修改工作状态", notes = "根据工作id修改工作状态", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "工作id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "工作状态", required = true, dataType = "int", paramType = "query")}
    )
    @ResponseBody
    @PutMapping(value = "/updS")
    public Result updS(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                       @RequestParam("noid") String noid,
                       @RequestParam("state") int state) {
        return workLogic.updS(noid, state);
    }


    //根据登录用户和工作状态查询工作列表
    //工作状态(0已报名，1已录用，2已完工)

    @ApiOperation(value = "根据登录用户和工作状态查询工作列表", notes = "根据登录用户和工作状态查询工作列表", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "普通用户id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态", required = true, dataType = "int", paramType = "query")
    })
    @ResponseBody
    @GetMapping(value = "/selS")
    public Result getByState(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                             @RequestParam("noid") String noid,
                             @RequestParam("state") int state) {
        return workLogic.getByState(noid, state);
    }

    //确认完工
    @ApiOperation(value = "确认完工", notes = "确认完工", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "普通用户id", required = true, dataType = "String", paramType = "query")
    })
    @ResponseBody
    @PutMapping(value = "/comp")
    public Result complete(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                           @RequestParam("noid") String noid) {
        return workLogic.updSByUser(noid);
    }

    //更新工作
    @ApiOperation(value = "更新工作", notes = "更新工作", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noid", value = "工作id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "part_id", value = "兼职id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "record_time", value = "录用时间", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userinfo_id", value = "登录用户id", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "工作状态", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "completion", value = "工作完成度", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "payamount", value = "付款金额", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "time", value = "工作时长", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "makespan", value = "完工时间", required = false, dataType = "String", paramType = "query")})
    @ResponseBody
    @PutMapping(value = "/upd")
    public Result upd(@RequestHeader(name = "Authorization", defaultValue = "token") String token, HttpSession session,
                      WorksheetModel work) {
        return workLogic.update(work);
    }

    //根据兼职id和用户信息详情id查询工作信息
    @ApiOperation(value = "根据兼职id和用户信息详情id查询工作信息", notes = "根据兼职id和用户信息详情id查询工作信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "part_id", value = "兼职id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userinfo_id", value = "用户详情id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "工作状态(0已报名，1已录用，2,工作中（已到岗），3已完工（已结算）)", required = true, dataType = "int", paramType = "query")}
    )
    @ResponseBody
    @PutMapping(value = "/updState")
    public Result updState(@RequestHeader(name = "Authorization", defaultValue = "token") String token,
                           @RequestParam("part_id") String part_id,
                           @RequestParam("userinfo_id") String userinfo_id,
                           @RequestParam("state") int state) {
        return workLogic.updState(part_id, userinfo_id, state);
    }
}
